PINN with Data


By Prof. Seungchul Lee
http://iai.postech.ac.kr/
Industrial AI Lab at POSTECH

Table of Contents

1. Pure Data-driven Approach¶

1.1. Big Data¶

InĀ [10]:
import os
os.environ["CUDA_DEVICE_ORDER"]="PCI_BUS_ID"
os.environ["CUDA_VISIBLE_DEVICES"]="1"
InĀ [11]:
import tensorflow as tf
import deepxde as dde
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
Using backend: pytorch

1.1.1. Define Parameters¶

InĀ [12]:
# Properties
rho = 1
mu = 1
u_in = 1
D = 1
L = 2

1.1.2. Data Load¶

InĀ [13]:
x_vel_xcor = pd.read_table('/mnt/disk1/seungmin/PINN/lecture/data/cae/x_vel_xcor_Re2_L2.txt')
x_vel_ycor = pd.read_table('/mnt/disk1/seungmin/PINN/lecture/data/cae/x_vel_ycor_Re2_L2.txt')
y_vel_xcor = pd.read_table('/mnt/disk1/seungmin/PINN/lecture/data/cae/y_vel_xcor_Re2_L2.txt')
y_vel_ycor = pd.read_table('/mnt/disk1/seungmin/PINN/lecture/data/cae/y_vel_ycor_Re2_L2.txt') 
p_xcor = pd.read_table('/mnt/disk1/seungmin/PINN/lecture/data/cae/p_xcor_Re2_L2.txt')
p_ycor = pd.read_table('/mnt/disk1/seungmin/PINN/lecture/data/cae/p_ycor_Re2_L2.txt') 
x_vel_xcor = np.array(x_vel_xcor)
x_vel_ycor = np.array(x_vel_ycor)
y_vel_xcor = np.array(y_vel_xcor)
y_vel_ycor = np.array(y_vel_ycor)
p_xcor = np.array(p_xcor)
p_ycor = np.array(p_ycor)
InĀ [14]:
observe_x = np.hstack([x_vel_xcor[:, 0].reshape(-1, 1), x_vel_ycor[:, 0].reshape(-1, 1)])

xvel_test = x_vel_xcor[:, 1].reshape(-1, 1)
yvel_test = y_vel_xcor[:, 1].reshape(-1, 1)
p_test = p_xcor[:, 1].reshape(-1, 1)
observe_y = np.hstack([xvel_test, yvel_test, p_test])
InĀ [15]:
plt.figure(figsize=(20, 4))
plt.scatter(observe_x[:, 0], observe_x[:, 1], c = observe_y[:, 0], s=6.5, cmap='jet')
plt.colorbar()
plt.clim((0, 1.5))
plt.scatter(observe_x[:, 0], observe_x[:, 1], s=0.1, alpha=0.5)

plt.xlim((0-L/2, L-L/2))
plt.ylim((0-D/2, D-D/2))
plt.xlabel('x-direction length')
plt.ylabel('Distance from middle of plates (m)')
plt.title('Velocity (u)')
plt.tight_layout()
plt.show()
InĀ [92]:
observe_u = dde.icbc.PointSetBC(observe_x, observe_y[:, 0].reshape(-1, 1), component=0)
observe_v = dde.icbc.PointSetBC(observe_x, observe_y[:, 1].reshape(-1, 1), component=1)
observe_p = dde.icbc.PointSetBC(observe_x, observe_y[:, 2].reshape(-1, 1), component=2)

1.1.3. Define Geometry¶

InĀ [93]:
geom = dde.geometry.Rectangle(xmin=[-L/2, -D/2], xmax=[L/2, D/2])
data = dde.data.PDE(geom,
                    None,
                    [observe_u, observe_v, observe_p], 
                    num_domain = 0, 
                    num_boundary = 0, 
                    num_test = 100)
Warning: 100 points required, but 120 points sampled.

1.1.4. Define Network and Hyper-parameters¶

InĀ [94]:
layer_size = [2] + [64] * 5 + [3]
activation = "tanh"
initializer = "Glorot uniform"

net = dde.maps.FNN(layer_size, activation, initializer)

model = dde.Model(data, net)
model.compile("adam", lr = 1e-3)
Compiling model...
'compile' took 0.000468 s

1.1.5. Train (Adam Optimizer)¶

InĀ [95]:
losshistory, train_state = model.train(epochs = 10000)
dde.saveplot(losshistory, train_state, issave = False, isplot = True)
Training model...

Step      Train loss                        Test loss                         Test metric
0         [1.21e+00, 4.80e-02, 2.43e+02]    [1.21e+00, 4.80e-02, 2.43e+02]    []  
1000      [6.64e-02, 8.08e-03, 2.00e+01]    [6.64e-02, 8.08e-03, 2.00e+01]    []  
2000      [6.25e-03, 4.68e-03, 1.34e+01]    [6.25e-03, 4.68e-03, 1.34e+01]    []  
3000      [5.41e-03, 2.33e-03, 9.69e+00]    [5.41e-03, 2.33e-03, 9.69e+00]    []  
4000      [3.33e-03, 1.25e-03, 7.10e+00]    [3.33e-03, 1.25e-03, 7.10e+00]    []  
5000      [2.05e-03, 1.34e-03, 5.16e+00]    [2.05e-03, 1.34e-03, 5.16e+00]    []  
6000      [1.55e-03, 1.42e-03, 3.72e+00]    [1.55e-03, 1.42e-03, 3.72e+00]    []  
7000      [1.38e-03, 1.53e-03, 2.71e+00]    [1.38e-03, 1.53e-03, 2.71e+00]    []  
8000      [1.30e-03, 1.30e-03, 2.02e+00]    [1.30e-03, 1.30e-03, 2.02e+00]    []  
9000      [1.19e-03, 1.00e-03, 1.53e+00]    [1.19e-03, 1.00e-03, 1.53e+00]    []  
10000     [1.06e-03, 7.69e-04, 1.23e+00]    [1.06e-03, 7.69e-04, 1.23e+00]    []  

Best model at step 10000:
  train loss: 1.23e+00
  test loss: 1.23e+00
  test metric: []

'train' took 78.963146 s

1.1.7. Train More (L-BFGS Optimizer)¶

InĀ [96]:
dde.optimizers.config.set_LBFGS_options()

model.compile("L-BFGS")
losshistory, train_state = model.train()
dde.saveplot(losshistory, train_state, issave = False, isplot = True)
Compiling model...
'compile' took 0.001038 s

Training model...

Step      Train loss                        Test loss                         Test metric
10000     [1.06e-03, 7.69e-04, 1.23e+00]    [1.06e-03, 7.69e-04, 1.23e+00]    []  
11000     [6.52e-04, 3.01e-04, 2.81e-03]    [6.52e-04, 3.01e-04, 2.81e-03]    []  
12000     [2.77e-04, 1.48e-04, 9.06e-04]    [2.77e-04, 1.48e-04, 9.06e-04]    []  
13000     [1.58e-04, 1.17e-04, 5.86e-04]    [1.58e-04, 1.17e-04, 5.86e-04]    []  
14000     [1.14e-04, 7.93e-05, 3.89e-04]    [1.14e-04, 7.93e-05, 3.89e-04]    []  
15000     [8.24e-05, 6.06e-05, 2.56e-04]    [8.24e-05, 6.06e-05, 2.56e-04]    []  
16000     [5.99e-05, 4.59e-05, 1.76e-04]    [5.99e-05, 4.59e-05, 1.76e-04]    []  
17000     [4.88e-05, 3.30e-05, 1.18e-04]    [4.88e-05, 3.30e-05, 1.18e-04]    []  
18000     [3.98e-05, 2.81e-05, 8.74e-05]    [3.98e-05, 2.81e-05, 8.74e-05]    []  
19000     [3.68e-05, 2.34e-05, 7.15e-05]    [3.68e-05, 2.34e-05, 7.15e-05]    []  
20000     [3.27e-05, 1.96e-05, 5.60e-05]    [3.27e-05, 1.96e-05, 5.60e-05]    []  
21000     [2.92e-05, 1.72e-05, 4.64e-05]    [2.92e-05, 1.72e-05, 4.64e-05]    []  
22000     [2.63e-05, 1.52e-05, 4.02e-05]    [2.63e-05, 1.52e-05, 4.02e-05]    []  
23000     [2.33e-05, 1.38e-05, 3.56e-05]    [2.33e-05, 1.38e-05, 3.56e-05]    []  
24000     [2.05e-05, 1.26e-05, 3.18e-05]    [2.05e-05, 1.26e-05, 3.18e-05]    []  
25000     [1.84e-05, 1.21e-05, 2.81e-05]    [1.84e-05, 1.21e-05, 2.81e-05]    []  

Best model at step 25000:
  train loss: 5.87e-05
  test loss: 5.87e-05
  test metric: []

'train' took 243.584611 s

1.1.8. Plot Results (Adam + L-BFGS)¶

InĀ [97]:
samples = geom.random_points(500000)
result = model.predict(samples)
color_legend = [[0, 1.5], [-0.3, 0.3], [0, 35]]
for idx in range(3):
    plt.figure(figsize = (20, 4))
    plt.scatter(samples[:, 0],
                samples[:, 1],
                c = result[:, idx],
                cmap = 'jet',
                s = 2)
    plt.colorbar()
    plt.clim(color_legend[idx])
    plt.xlim((0-L/2, L-L/2))
    plt.ylim((0-D/2, D-D/2))
    plt.tight_layout()
    plt.show()
InĀ [98]:
# result_total = model.predict(observe_x)
# np.save('./data_plot/bigdata_total_x', observe_x[:, 0])
# np.save('./data_plot/bigdata_total_y', observe_x[:, 1])
# np.save('./data_plot/bigdata_total_u', result_total[:, 0])
# np.save('./data_plot/bigdata_total_v', result_total[:, 1])
# np.save('./data_plot/bigdata_total_p', result_total[:, 2])
InĀ [63]:
# plt.figure(figsize=(20, 4))
# plt.scatter(observe_x[:, 0], observe_x[:, 1], c=result_total[:, 0], cmap='jet')
Out[63]:
<matplotlib.collections.PathCollection at 0x7f8229fb85d0>
InĀ [54]:
y0 = np.zeros([1000, 1])
y03 = np.ones([1000, 1])*0.3
yinv03 = np.ones([1000, 1])*(-0.3)
x = np.linspace(-1, 1, 1000).reshape(1000,1)
draw0 = np.hstack([x, y0])
draw03 = np.hstack([x, y03])
drawinv03 = np.hstack([x, yinv03])

result_draw0 = model.predict(draw0)
result_draw03 = model.predict(draw03)
result_drawinv03 = model.predict(drawinv03)

result = model.predict(samples)
InĀ [55]:
# np.save('./data_plot/bigdata_x', x)
# np.save('./data_plot/bigdata_y0_u', result_draw0[:, 0])
# np.save('./data_plot/bigdata_y0_v', result_draw0[:, 1])
# np.save('./data_plot/bigdata_y0_p', result_draw0[:, 2])
# np.save('./data_plot/bigdata_y03_u', result_draw03[:, 0])
# np.save('./data_plot/bigdata_y03_v', result_draw03[:, 1])
# np.save('./data_plot/bigdata_y03_p', result_draw03[:, 2])
# np.save('./data_plot/bigdata_yinv03_u', result_drawinv03[:, 0])
# np.save('./data_plot/bigdata_yinv03_v', result_drawinv03[:, 1])
# np.save('./data_plot/bigdata_yinv03_p', result_drawinv03[:, 2])
InĀ [55]:
total_x = np.load('./data_plot/bigdata_total_x.npy')
total_p = np.load('./data_plot/bigdata_total_p.npy')
InĀ [56]:
plt.figure(figsize=(20,4))
plt.scatter(total_x, total_p, s=9, color='k', label='CFD')
Out[56]:
<matplotlib.collections.PathCollection at 0x7f333c33a410>
InĀ [40]:
b_x = np.load('./data_plot/bigdata_x.npy')
b_y0_u = np.load('./data_plot/bigdata_y0_u.npy')
b_y0_v = np.load('./data_plot/bigdata_y0_v.npy')
b_y0_p = np.load('./data_plot/bigdata_y0_p.npy')
b_y03_u = np.load('./data_plot/bigdata_y03_u.npy')
b_y03_v = np.load('./data_plot/bigdata_y03_v.npy')
b_y03_p = np.load('./data_plot/bigdata_y03_p.npy')
b_yinv03_u = np.load('./data_plot/bigdata_yinv03_u.npy')
b_yinv03_v = np.load('./data_plot/bigdata_yinv03_v.npy')
b_yinv03_p = np.load('./data_plot/bigdata_yinv03_p.npy')
InĀ [62]:
cfd_x_y0 = np.load('./data_plot/cfd_x_y0.npy')
cfd_x_y03 = np.load('./data_plot/cfd_x_y03.npy')
cfd_x_yinv03 = np.load('./data_plot/cfd_x_yinv03.npy')
cfd_y0_u = np.load('./data_plot/cfd_y0_u.npy')
cfd_y0_v = np.load('./data_plot/cfd_y0_v.npy')
cfd_y0_p = np.load('./data_plot/cfd_y0_p.npy')
cfd_y03_u = np.load('./data_plot/cfd_y03_u.npy')
cfd_y03_v = np.load('./data_plot/cfd_y03_v.npy')
cfd_y03_p = np.load('./data_plot/cfd_y03_p.npy')
cfd_yinv03_u = np.load('./data_plot/cfd_yinv03_u.npy')
cfd_yinv03_v = np.load('./data_plot/cfd_yinv03_v.npy')
cfd_yinv03_p = np.load('./data_plot/cfd_yinv03_p.npy')
InĀ [43]:
plt.figure(figsize=(20,4))
plt.plot(b_x, b_y0_p, color='royalblue', label='y=0', linewidth=3)
plt.plot(b_x, b_y03_p, color='green', label='y=0.5', linewidth=3)
plt.plot(b_x, b_yinv03_p, color='orange', label='y=-0.5', linewidth=3)
plt.scatter(cfd_x_y0, cfd_y0_p, s=9, color='k', label='CFD')
plt.scatter(cfd_x_y03, cfd_y03_p, s=9, color='k')
plt.scatter(cfd_x_yinv03, cfd_yinv03_p, s=9, color='k')

plt.legend()
plt.show()

1.2. Small Data¶

InĀ [64]:
import deepxde as dde
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

1.2.1. Define Parameters¶

InĀ [65]:
# Properties
mu = 1
rho = 1
u_in = 1
D = 1
L = 2

1.2.2. Data Indexing¶

InĀ [66]:
idx_025 = np.isclose(x_vel_xcor[:, 0], 0.25, atol=0.005)
idx_inv_025 = np.isclose(x_vel_xcor[:, 0], -0.25, atol=0.005)
idx_075 = np.isclose(x_vel_xcor[:, 0], 0.75, atol=0.003)
idx_inv_075 = np.isclose(x_vel_xcor[:, 0], -0.75, atol=0.003)
idx_05 = np.isclose(x_vel_xcor[:, 0], 0.5, atol=0.005)
idx_inv_05 = np.isclose(x_vel_xcor[:, 0], -0.5, atol=0.005)
idx_0 = np.isclose(x_vel_xcor[:, 0], 0, atol=0.005)
idx_1 = np.isclose(x_vel_xcor[:, 0], 1, atol=0.005)
idx_inv_1 = np.isclose(x_vel_xcor[:, 0], -1, atol=0.005)
InĀ [67]:
xy_025 = np.hstack([x_vel_xcor[:, 0][idx_025].reshape(-1, 1), x_vel_ycor[:, 0][idx_025].reshape(-1, 1)])
xy_inv_025 = np.hstack([x_vel_xcor[:, 0][idx_inv_025].reshape(-1, 1), x_vel_ycor[:, 0][idx_inv_025].reshape(-1, 1)])
xy_075 = np.hstack([x_vel_xcor[:, 0][idx_075].reshape(-1, 1), x_vel_ycor[:, 0][idx_075].reshape(-1, 1)])
xy_inv_075 = np.hstack([x_vel_xcor[:, 0][idx_inv_075].reshape(-1, 1), x_vel_ycor[:, 0][idx_inv_075].reshape(-1, 1)])

observe_x = np.vstack([xy_025, xy_inv_025, xy_075, xy_inv_075])

xvel_025 = x_vel_xcor[:, 1][idx_025].reshape(-1, 1)
xvel_inv_025 = x_vel_xcor[:, 1][idx_inv_025].reshape(-1, 1)
xvel_075 = x_vel_xcor[:, 1][idx_075].reshape(-1, 1)
xvel_inv_075 = x_vel_xcor[:, 1][idx_inv_075].reshape(-1, 1)

yvel_025 = y_vel_xcor[:, 1][idx_025].reshape(-1, 1)
yvel_inv_025 = y_vel_xcor[:, 1][idx_inv_025].reshape(-1, 1)
yvel_075 = y_vel_xcor[:, 1][idx_075].reshape(-1, 1)
yvel_inv_075 = y_vel_xcor[:, 1][idx_inv_075].reshape(-1, 1)

p_025 = p_xcor[:, 1][idx_025].reshape(-1, 1)
p_inv_025 = p_xcor[:, 1][idx_inv_025].reshape(-1, 1)
p_075 = p_xcor[:, 1][idx_075].reshape(-1, 1)
p_inv_075 = p_xcor[:, 1][idx_inv_075].reshape(-1, 1)

xvel_test = np.vstack([xvel_025, xvel_inv_025, xvel_075, xvel_inv_075])
yvel_test = np.vstack([yvel_025, yvel_inv_025, yvel_075, yvel_inv_075])
p_test = np.vstack([p_025, p_inv_025, p_075, p_inv_075])
observe_y = np.hstack([xvel_test, yvel_test, p_test])
InĀ [71]:
plt.figure(figsize=(20, 4))
plt.scatter(observe_x[:, 0], observe_x[:, 1], c = observe_y[:, 0], s=6.5, cmap='jet')
plt.scatter(observe_x[:, 0], observe_x[:, 1], s=1, alpha=0.5)
plt.colorbar()
plt.clim((0, 1.5))
plt.xlim((0-L/2, L-L/2))
plt.ylim((0-D/2, D-D/2))
plt.xlabel('x-direction length')
plt.ylabel('Distance from middle of plates (m)')
plt.title('Velocity (u)')
plt.tight_layout()
plt.show()
InĀ [72]:
observe_u = dde.icbc.PointSetBC(observe_x, observe_y[:, 0].reshape(-1, 1), component=0)
observe_v = dde.icbc.PointSetBC(observe_x, observe_y[:, 1].reshape(-1, 1), component=1)
observe_p = dde.icbc.PointSetBC(observe_x, observe_y[:, 2].reshape(-1, 1), component=2)

1.2.3. Define Geometry¶

InĀ [73]:
geom = dde.geometry.Rectangle(xmin=[-L/2, -D/2], xmax=[L/2, D/2])
data = dde.data.PDE(geom,
                    None,
                    [observe_u, observe_v, observe_p], 
                    num_domain = 0, 
                    num_boundary = 0, 
                    num_test = 100)
Warning: 100 points required, but 120 points sampled.

1.2.4. Define Network and Hyper-parameters¶

InĀ [74]:
layer_size = [2] + [64] * 5 + [3]
activation = "tanh"
initializer = "Glorot uniform"

net = dde.maps.FNN(layer_size, activation, initializer)

model = dde.Model(data, net)
model.compile("adam", lr = 1e-3)
Compiling model...
'compile' took 0.000527 s

1.2.5. Train (Adam Optimizer)¶

InĀ [75]:
losshistory, train_state = model.train(epochs = 10000)
dde.saveplot(losshistory, train_state, issave = False, isplot = True)
Training model...

Step      Train loss                        Test loss                         Test metric
0         [1.19e+00, 2.28e-02, 1.94e+02]    [1.19e+00, 2.28e-02, 1.94e+02]    []  
1000      [1.81e-01, 5.40e-03, 1.57e-01]    [1.81e-01, 5.40e-03, 1.57e-01]    []  
2000      [1.27e-02, 4.69e-03, 1.55e-01]    [1.27e-02, 4.69e-03, 1.55e-01]    []  
3000      [6.03e-04, 7.90e-04, 1.22e-02]    [6.03e-04, 7.90e-04, 1.22e-02]    []  
4000      [3.08e-04, 2.24e-04, 2.32e-03]    [3.08e-04, 2.24e-04, 2.32e-03]    []  
5000      [1.02e-04, 9.41e-05, 9.98e-05]    [1.02e-04, 9.41e-05, 9.98e-05]    []  
6000      [4.85e-05, 6.19e-05, 5.44e-05]    [4.85e-05, 6.19e-05, 5.44e-05]    []  
7000      [2.80e-05, 4.45e-05, 3.97e-05]    [2.80e-05, 4.45e-05, 3.97e-05]    []  
8000      [2.28e-04, 7.81e-05, 9.42e-03]    [2.28e-04, 7.81e-05, 9.42e-03]    []  
9000      [1.31e-05, 2.65e-05, 3.01e-05]    [1.31e-05, 2.65e-05, 3.01e-05]    []  
10000     [1.01e-05, 2.15e-05, 2.80e-05]    [1.01e-05, 2.15e-05, 2.80e-05]    []  

Best model at step 10000:
  train loss: 5.96e-05
  test loss: 5.96e-05
  test metric: []

'train' took 79.150069 s

1.2.7. Train More (L-BFGS Optimizer)¶

InĀ [76]:
dde.optimizers.config.set_LBFGS_options()

model.compile("L-BFGS")
losshistory, train_state = model.train()
dde.saveplot(losshistory, train_state, issave = False, isplot = True)
Compiling model...
'compile' took 0.000613 s

Training model...

Step      Train loss                        Test loss                         Test metric
10000     [1.01e-05, 2.15e-05, 2.80e-05]    [1.01e-05, 2.15e-05, 2.80e-05]    []  
11000     [1.01e-05, 2.14e-05, 2.79e-05]    [1.01e-05, 2.14e-05, 2.79e-05]    []  
12000     [1.01e-05, 2.13e-05, 2.79e-05]    [1.01e-05, 2.13e-05, 2.79e-05]    []  
13000     [1.00e-05, 2.13e-05, 2.79e-05]    [1.00e-05, 2.13e-05, 2.79e-05]    []  
14000     [1.00e-05, 2.12e-05, 2.79e-05]    [1.00e-05, 2.12e-05, 2.79e-05]    []  
15000     [1.00e-05, 2.11e-05, 2.79e-05]    [1.00e-05, 2.11e-05, 2.79e-05]    []  
16000     [9.98e-06, 2.11e-05, 2.79e-05]    [9.98e-06, 2.11e-05, 2.79e-05]    []  
17000     [9.96e-06, 2.10e-05, 2.79e-05]    [9.96e-06, 2.10e-05, 2.79e-05]    []  
18000     [9.94e-06, 2.09e-05, 2.79e-05]    [9.94e-06, 2.09e-05, 2.79e-05]    []  
19000     [9.92e-06, 2.09e-05, 2.79e-05]    [9.92e-06, 2.09e-05, 2.79e-05]    []  
20000     [9.90e-06, 2.08e-05, 2.79e-05]    [9.90e-06, 2.08e-05, 2.79e-05]    []  
21000     [9.88e-06, 2.07e-05, 2.79e-05]    [9.88e-06, 2.07e-05, 2.79e-05]    []  
22000     [9.86e-06, 2.07e-05, 2.79e-05]    [9.86e-06, 2.07e-05, 2.79e-05]    []  
23000     [9.85e-06, 2.06e-05, 2.79e-05]    [9.85e-06, 2.06e-05, 2.79e-05]    []  
24000     [9.83e-06, 2.06e-05, 2.79e-05]    [9.83e-06, 2.06e-05, 2.79e-05]    []  
25000     [9.81e-06, 2.05e-05, 2.79e-05]    [9.81e-06, 2.05e-05, 2.79e-05]    []  

Best model at step 25000:
  train loss: 5.83e-05
  test loss: 5.83e-05
  test metric: []

'train' took 82.598389 s

1.2.8. Plot Results (Adam + L-BFGS)¶

InĀ [77]:
samples = geom.random_points(500000)
result = model.predict(samples)
color_legend = [[0, 1.5], [-0.3, 0.3], [0, 35]]
for idx in range(3):
    plt.figure(figsize = (20, 4))
    plt.scatter(samples[:, 0],
                samples[:, 1],
                c = result[:, idx],
                cmap = 'jet',
                s = 2)
    plt.colorbar()
    plt.clim(color_legend[idx])
    plt.xlim((0-L/2, L-L/2))
    plt.ylim((0-D/2, D-D/2))
    plt.tight_layout()
    plt.show()
InĀ [78]:
y0 = np.zeros([1000, 1])
y03 = np.ones([1000, 1])*0.3
yinv03 = np.ones([1000, 1])*(-0.3)
x = np.linspace(-1, 1, 1000).reshape(1000,1)
draw0 = np.hstack([x, y0])
draw03 = np.hstack([x, y03])
drawinv03 = np.hstack([x, yinv03])

result_draw0 = model.predict(draw0)
result_draw03 = model.predict(draw03)
result_drawinv03 = model.predict(drawinv03)
InĀ [79]:
# np.save('./data_plot/smalldata_x', x)
# np.save('./data_plot/smalldata_y0_u', result_draw0[:, 0])
# np.save('./data_plot/smalldata_y0_v', result_draw0[:, 1])
# np.save('./data_plot/smalldata_y0_p', result_draw0[:, 2])
# np.save('./data_plot/smalldata_y03_u', result_draw03[:, 0])
# np.save('./data_plot/smalldata_y03_v', result_draw03[:, 1])
# np.save('./data_plot/smalldata_y03_p', result_draw03[:, 2])
# np.save('./data_plot/smalldata_yinv03_u', result_drawinv03[:, 0])
# np.save('./data_plot/smalldata_yinv03_v', result_drawinv03[:, 1])
# np.save('./data_plot/smalldata_yinv03_p', result_drawinv03[:, 2])
InĀ [85]:
# plt.figure(figsize=(20, 4))
# plt.scatter(observe_x[:, 0], observe_x[:, 1], c=result_total[:, 0], cmap='jet')
# plt.clim(0,1.5)
InĀ [Ā ]:
plt.figure(figsize=(20,4))
plt.plot(x, a, color='royalblue', label='y=0', linewidth=3)
plt.plot(x, result_draw03[:, 1], color='green', label='y=0.5', linewidth=3)
plt.plot(x, result_drawinv03[:, 1], color='orange', label='y=-0.5', linewidth=3)
plt.scatter(observe_x[:, 0][idx0], observe_y[:, 1][idx0], s=9, color='k', label='CFD')
plt.scatter(observe_x[:, 0][idx03], observe_y[:, 1][idx03], s=9, color='k')
plt.scatter(observe_x[:, 0][idxinv03], observe_y[:, 1][idxinv03], s=9, color='k')

plt.legend()
plt.show()
InĀ [46]:
np.save('./data_plot/smaldata_total_p', result.reshape(-1, 1))
InĀ [47]:
x = np.load('./data_plot/smaldata_total_x.npy')
y= np.load('./data_plot/smaldata_total_y.npy')
p= np.load('./data_plot/smaldata_total_p.npy')
InĀ [50]:
plt.scatter(x, y, c=p, cmap='jet')
# plt.clim(0, 35)

2. PINN with Data¶

2.1. Physics + Small Data¶

2.1.1. Define Parameters¶

InĀ [16]:
# Properties
rho = 1
mu = 1
u_in = 1
D = 1
L = 2
InĀ [17]:
idx_025 = np.isclose(x_vel_xcor[:, 0], 0.25, atol=0.005)
idx_inv_025 = np.isclose(x_vel_xcor[:, 0], -0.25, atol=0.005)
idx_075 = np.isclose(x_vel_xcor[:, 0], 0.75, atol=0.003)
idx_inv_075 = np.isclose(x_vel_xcor[:, 0], -0.75, atol=0.003)
idx_05 = np.isclose(x_vel_xcor[:, 0], 0.5, atol=0.005)
idx_inv_05 = np.isclose(x_vel_xcor[:, 0], -0.5, atol=0.005)
idx_0 = np.isclose(x_vel_xcor[:, 0], 0, atol=0.005)
idx_1 = np.isclose(x_vel_xcor[:, 0], 1, atol=0.005)
idx_inv_1 = np.isclose(x_vel_xcor[:, 0], -1, atol=0.005)
InĀ [18]:
xy_025 = np.hstack([x_vel_xcor[:, 0][idx_025].reshape(-1, 1), x_vel_ycor[:, 0][idx_025].reshape(-1, 1)])
xy_inv_025 = np.hstack([x_vel_xcor[:, 0][idx_inv_025].reshape(-1, 1), x_vel_ycor[:, 0][idx_inv_025].reshape(-1, 1)])
xy_075 = np.hstack([x_vel_xcor[:, 0][idx_075].reshape(-1, 1), x_vel_ycor[:, 0][idx_075].reshape(-1, 1)])
xy_inv_075 = np.hstack([x_vel_xcor[:, 0][idx_inv_075].reshape(-1, 1), x_vel_ycor[:, 0][idx_inv_075].reshape(-1, 1)])

observe_x = np.vstack([xy_025, xy_inv_025, xy_075, xy_inv_075])

xvel_025 = x_vel_xcor[:, 1][idx_025].reshape(-1, 1)
xvel_inv_025 = x_vel_xcor[:, 1][idx_inv_025].reshape(-1, 1)
xvel_075 = x_vel_xcor[:, 1][idx_075].reshape(-1, 1)
xvel_inv_075 = x_vel_xcor[:, 1][idx_inv_075].reshape(-1, 1)

yvel_025 = y_vel_xcor[:, 1][idx_025].reshape(-1, 1)
yvel_inv_025 = y_vel_xcor[:, 1][idx_inv_025].reshape(-1, 1)
yvel_075 = y_vel_xcor[:, 1][idx_075].reshape(-1, 1)
yvel_inv_075 = y_vel_xcor[:, 1][idx_inv_075].reshape(-1, 1)

p_025 = p_xcor[:, 1][idx_025].reshape(-1, 1)
p_inv_025 = p_xcor[:, 1][idx_inv_025].reshape(-1, 1)
p_075 = p_xcor[:, 1][idx_075].reshape(-1, 1)
p_inv_075 = p_xcor[:, 1][idx_inv_075].reshape(-1, 1)

xvel_test = np.vstack([xvel_025, xvel_inv_025, xvel_075, xvel_inv_075])
yvel_test = np.vstack([yvel_025, yvel_inv_025, yvel_075, yvel_inv_075])
p_test = np.vstack([p_025, p_inv_025, p_075, p_inv_075])
observe_y = np.hstack([xvel_test, yvel_test, p_test])

2.1.2. Data Indexing¶

InĀ [19]:
plt.figure(figsize=(20, 4))
plt.scatter(observe_x[:, 0], observe_x[:, 1], c = observe_y[:, 0], s=6.5, cmap='jet')
plt.scatter(observe_x[:, 0], observe_x[:, 1], s=1, alpha=0.5)
plt.colorbar()
plt.clim((0, 1.5))
plt.xlim((0-L/2, L-L/2))
plt.ylim((0-D/2, D-D/2))
plt.xlabel('x-direction length')
plt.ylabel('Distance from middle of plates (m)')
plt.title('Velocity (u)')
plt.tight_layout()
plt.show()
InĀ [20]:
observe_u = dde.icbc.PointSetBC(observe_x, observe_y[:, 0].reshape(-1, 1), component=0)
observe_v = dde.icbc.PointSetBC(observe_x, observe_y[:, 1].reshape(-1, 1), component=1)
observe_p = dde.icbc.PointSetBC(observe_x, observe_y[:, 2].reshape(-1, 1), component=2)

2.1.3. Define PDE with Boundary & Initial Conditions¶

InĀ [21]:
def boundary_wall(X, on_boundary):
    on_wall = np.logical_and(np.logical_or(np.isclose(X[1], -D/2), np.isclose(X[1], D/2)), on_boundary)
    return on_wall

def boundary_inlet(X, on_boundary):
    return on_boundary and np.isclose(X[0], -L/2)

def boundary_outlet(X, on_boundary):### 6.3.2. Define PDE with Boundary & Initial Conditions
    return on_boundary and np.isclose(X[0], L/2)
InĀ [22]:
def pde(X, Y):
    du_x = dde.grad.jacobian(Y, X, i = 0, j = 0)
    du_y = dde.grad.jacobian(Y, X, i = 0, j = 1)
    dv_x = dde.grad.jacobian(Y, X, i = 1, j = 0)
    dv_y = dde.grad.jacobian(Y, X, i = 1, j = 1)
    dp_x = dde.grad.jacobian(Y, X, i = 2, j = 0)
    dp_y = dde.grad.jacobian(Y, X, i = 2, j = 1)
    du_xx = dde.grad.hessian(Y, X, i = 0, j = 0, component = 0)
    du_yy = dde.grad.hessian(Y, X, i = 1, j = 1, component = 0)
    dv_xx = dde.grad.hessian(Y, X, i = 0, j = 0, component = 1)
    dv_yy = dde.grad.hessian(Y, X, i = 1, j = 1, component = 1)
    
    pde_u = Y[:,0:1]*du_x + Y[:,1:2]*du_y + 1/rho * dp_x - (mu/rho)*(du_xx + du_yy)
    pde_v = Y[:,0:1]*dv_x + Y[:,1:2]*dv_y + 1/rho * dp_y - (mu/rho)*(dv_xx + dv_yy)
    pde_cont = du_x + dv_y

    return [pde_u, pde_v, pde_cont]

2.1.4. Define Geometry and Implement Boundary Condition¶

InĀ [23]:
geom = dde.geometry.Rectangle(xmin=[-L/2, -D/2], xmax=[L/2, D/2])

bc_wall_u = dde.DirichletBC(geom, lambda X: 0., boundary_wall, component = 0)
bc_wall_v = dde.DirichletBC(geom, lambda X: 0., boundary_wall, component = 1)

bc_inlet_u = dde.DirichletBC(geom, lambda X: u_in, boundary_inlet, component = 0)
bc_inlet_v = dde.DirichletBC(geom, lambda X: 0., boundary_inlet, component = 1)

bc_outlet_p = dde.DirichletBC(geom, lambda X: 0., boundary_outlet, component = 2)
bc_outlet_v = dde.DirichletBC(geom, lambda X: 0., boundary_outlet, component = 1)
InĀ [24]:
geom = dde.geometry.Rectangle(xmin=[-L/2, -D/2], xmax=[L/2, D/2])
data = dde.data.PDE(geom,
                    pde,
                    [bc_wall_u, bc_wall_v, bc_inlet_u, bc_inlet_v, bc_outlet_p, bc_outlet_v, observe_u, observe_v, observe_p], 
                    num_domain = 1000, 
                    num_boundary = 500, 
                    num_test = 1000,
                    train_distribution = 'LHS')
Warning: 1000 points required, but 1035 points sampled.
InĀ [25]:
plt.figure(figsize = (20,4))
plt.scatter(data.train_x_all[:,0], data.train_x_all[:,1], s = 0.5)
plt.scatter(observe_x[:, 0], observe_x[:, 1], c = observe_y[:, 0], s=6.5, cmap='jet')
plt.colorbar()
plt.clim((0, 1.5))
plt.scatter(observe_x[:, 0], observe_x[:, 1], s=1, alpha=0.5)
plt.xlim((0-L/2, L-L/2))
plt.ylim((0-D/2, D-D/2))
plt.xlabel('x-direction length')
plt.ylabel('Distance from middle of plates (m)')
plt.title('Velocity (u)')
plt.tight_layout()
plt.show()

2.1.5. Define Network and Hyper-parameters¶

InĀ [26]:
layer_size = [2] + [64] * 5 + [3]
activation = "tanh"
initializer = "Glorot uniform"

net = dde.maps.FNN(layer_size, activation, initializer)

model = dde.Model(data, net)
model.compile("adam", lr = 1e-3, loss_weights=[1, 1, 1, 1, 1, 1, 1, 1, 1, 9, 9, 9])
Compiling model...
'compile' took 0.000568 s

2.1.6. Train (Adam Optimizer)¶

InĀ [27]:
losshistory, train_state = model.train(epochs = 10000)
dde.saveplot(losshistory, train_state, issave = False, isplot = True)### 7.2.5. Train (Adam Optimizer)
Training model...

Step      Train loss                                                                                                                  Test loss                                                                                                                   Test metric
0         [1.32e-02, 8.46e-03, 5.74e-03, 5.12e-04, 4.60e-03, 1.06e+00, 7.19e-03, 1.10e-02, 7.19e-03, 1.05e+01, 6.09e-02, 1.76e+03]    [1.36e-02, 7.90e-03, 5.91e-03, 5.12e-04, 4.60e-03, 1.06e+00, 7.19e-03, 1.10e-02, 7.19e-03, 1.05e+01, 6.09e-02, 1.76e+03]    []  
1000      [6.13e-02, 2.83e-02, 9.31e-02, 5.14e-02, 1.86e-03, 5.55e-02, 2.38e-03, 2.92e-03, 7.86e-05, 4.22e-02, 1.60e-02, 5.60e-01]    [5.83e-02, 3.07e-02, 1.18e-01, 5.14e-02, 1.86e-03, 5.55e-02, 2.38e-03, 2.92e-03, 7.86e-05, 4.22e-02, 1.60e-02, 5.60e-01]    []  
2000      [1.53e-02, 1.15e-02, 6.33e-02, 1.78e-02, 7.05e-04, 6.04e-02, 1.93e-03, 6.68e-04, 3.90e-04, 2.73e-02, 1.07e-02, 1.82e-01]    [1.89e-02, 1.48e-02, 6.55e-02, 1.78e-02, 7.05e-04, 6.04e-02, 1.93e-03, 6.68e-04, 3.90e-04, 2.73e-02, 1.07e-02, 1.82e-01]    []  
3000      [1.61e-01, 4.75e-02, 7.52e-02, 1.38e-02, 1.05e-03, 6.58e-02, 1.49e-03, 3.84e-03, 5.32e-04, 2.66e-02, 1.60e-02, 1.07e-01]    [1.30e-01, 5.09e-02, 5.95e-02, 1.38e-02, 1.05e-03, 6.58e-02, 1.49e-03, 3.84e-03, 5.32e-04, 2.66e-02, 1.60e-02, 1.07e-01]    []  
4000      [2.03e-01, 7.21e-02, 8.32e-02, 1.45e-02, 9.93e-04, 6.45e-02, 2.06e-03, 6.43e-03, 3.29e-04, 2.55e-02, 1.71e-02, 7.20e-02]    [1.38e-01, 6.86e-02, 6.42e-02, 1.45e-02, 9.93e-04, 6.45e-02, 2.06e-03, 6.43e-03, 3.29e-04, 2.55e-02, 1.71e-02, 7.20e-02]    []  
5000      [1.25e-02, 6.51e-03, 8.17e-02, 1.56e-02, 5.72e-04, 6.13e-02, 3.21e-03, 5.07e-03, 7.60e-05, 2.36e-02, 1.32e-02, 5.15e-02]    [1.11e-02, 9.55e-03, 6.43e-02, 1.56e-02, 5.72e-04, 6.13e-02, 3.21e-03, 5.07e-03, 7.60e-05, 2.36e-02, 1.32e-02, 5.15e-02]    []  
6000      [3.37e-03, 3.17e-03, 8.00e-02, 1.61e-02, 5.27e-04, 5.86e-02, 4.22e-03, 1.32e-04, 2.30e-05, 2.32e-02, 1.28e-02, 2.98e-02]    [4.69e-03, 6.41e-03, 6.59e-02, 1.61e-02, 5.27e-04, 5.86e-02, 4.22e-03, 1.32e-04, 2.30e-05, 2.32e-02, 1.28e-02, 2.98e-02]    []  
7000      [4.62e-03, 2.99e-03, 7.59e-02, 1.66e-02, 4.91e-04, 5.58e-02, 5.64e-03, 2.26e-03, 8.90e-06, 2.27e-02, 1.23e-02, 3.05e-02]    [5.44e-03, 5.81e-03, 6.61e-02, 1.66e-02, 4.91e-04, 5.58e-02, 5.64e-03, 2.26e-03, 8.90e-06, 2.27e-02, 1.23e-02, 3.05e-02]    []  
8000      [2.83e-03, 2.97e-03, 7.11e-02, 1.67e-02, 4.83e-04, 5.31e-02, 7.49e-03, 2.09e-04, 5.98e-06, 2.23e-02, 1.18e-02, 2.24e-02]    [4.14e-03, 5.96e-03, 6.58e-02, 1.67e-02, 4.83e-04, 5.31e-02, 7.49e-03, 2.09e-04, 5.98e-06, 2.23e-02, 1.18e-02, 2.24e-02]    []  
9000      [5.24e-03, 3.43e-03, 6.67e-02, 1.66e-02, 5.24e-04, 5.04e-02, 9.70e-03, 1.77e-03, 1.32e-05, 2.20e-02, 1.17e-02, 2.36e-02]    [5.66e-03, 6.62e-03, 6.57e-02, 1.66e-02, 5.24e-04, 5.04e-02, 9.70e-03, 1.77e-03, 1.32e-05, 2.20e-02, 1.17e-02, 2.36e-02]    []  
10000     [4.81e-03, 3.14e-03, 6.24e-02, 1.69e-02, 6.13e-04, 4.70e-02, 1.16e-02, 2.70e-03, 2.41e-05, 2.15e-02, 1.16e-02, 2.32e-02]    [5.87e-03, 7.55e-03, 6.34e-02, 1.69e-02, 6.13e-04, 4.70e-02, 1.16e-02, 2.70e-03, 2.41e-05, 2.15e-02, 1.16e-02, 2.32e-02]    []  

Best model at step 10000:
  train loss: 2.06e-01
  test loss: 2.12e-01
  test metric: []

'train' took 401.244833 s

2.1.7. Train More (L-BFGS Optimizer)¶

InĀ [28]:
dde.optimizers.config.set_LBFGS_options()

model.compile("L-BFGS", loss_weights=[1, 1, 1, 1, 1, 1, 1, 1, 1, 9, 9, 9])
losshistory, train_state = model.train()
dde.saveplot(losshistory, train_state, issave = False, isplot = True)### 7.2.7. Train More (L-BFGS Optimizer)
Compiling model...
'compile' took 0.001069 s

Training model...

Step      Train loss                                                                                                                  Test loss                                                                                                                   Test metric
10000     [4.81e-03, 3.14e-03, 6.24e-02, 1.69e-02, 6.13e-04, 4.70e-02, 1.16e-02, 2.70e-03, 2.41e-05, 2.15e-02, 1.16e-02, 2.32e-02]    [5.87e-03, 7.55e-03, 6.34e-02, 1.69e-02, 6.13e-04, 4.70e-02, 1.16e-02, 2.70e-03, 2.41e-05, 2.15e-02, 1.16e-02, 2.32e-02]    []  
11000     [3.94e-03, 2.81e-03, 3.17e-02, 1.51e-02, 2.45e-03, 1.37e-02, 2.00e-02, 3.91e-05, 7.87e-05, 1.23e-02, 4.43e-03, 3.14e-03]    [5.88e-03, 4.62e-03, 3.72e-02, 1.51e-02, 2.45e-03, 1.37e-02, 2.00e-02, 3.91e-05, 7.87e-05, 1.23e-02, 4.43e-03, 3.14e-03]    []  
12000     [2.84e-03, 2.68e-03, 1.13e-02, 1.11e-02, 6.55e-04, 1.17e-02, 1.14e-02, 1.33e-05, 1.39e-05, 5.25e-03, 2.03e-03, 9.97e-04]    [4.76e-03, 3.99e-03, 1.39e-02, 1.11e-02, 6.55e-04, 1.17e-02, 1.14e-02, 1.33e-05, 1.39e-05, 5.25e-03, 2.03e-03, 9.97e-04]    []  
13000     [1.55e-03, 2.08e-03, 3.43e-03, 9.29e-03, 3.94e-04, 8.83e-03, 3.42e-03, 1.11e-04, 2.42e-05, 9.18e-04, 5.14e-04, 7.17e-04]    [2.55e-03, 3.30e-03, 3.46e-03, 9.29e-03, 3.94e-04, 8.83e-03, 3.42e-03, 1.11e-04, 2.42e-05, 9.18e-04, 5.14e-04, 7.17e-04]    []  
14000     [9.09e-04, 8.09e-04, 2.03e-03, 9.57e-03, 3.15e-04, 6.40e-03, 2.22e-03, 2.58e-05, 1.89e-05, 3.17e-04, 2.74e-04, 6.01e-04]    [1.42e-03, 1.73e-03, 1.77e-03, 9.57e-03, 3.15e-04, 6.40e-03, 2.22e-03, 2.58e-05, 1.89e-05, 3.17e-04, 2.74e-04, 6.01e-04]    []  
15000     [5.84e-04, 4.65e-04, 1.27e-03, 8.64e-03, 3.16e-04, 5.45e-03, 2.27e-03, 8.55e-06, 1.04e-06, 1.68e-04, 2.27e-04, 3.66e-04]    [1.17e-03, 9.50e-04, 1.06e-03, 8.64e-03, 3.16e-04, 5.45e-03, 2.27e-03, 8.55e-06, 1.04e-06, 1.68e-04, 2.27e-04, 3.66e-04]    []  
16000     [3.03e-04, 4.14e-04, 9.51e-04, 7.51e-03, 3.54e-04, 5.04e-03, 2.76e-03, 2.32e-06, 2.52e-07, 1.44e-04, 2.12e-04, 3.59e-04]    [6.60e-04, 9.15e-04, 7.00e-04, 7.51e-03, 3.54e-04, 5.04e-03, 2.76e-03, 2.32e-06, 2.52e-07, 1.44e-04, 2.12e-04, 3.59e-04]    []  
17000     [2.83e-04, 3.57e-04, 7.89e-04, 7.28e-03, 3.66e-04, 4.54e-03, 2.75e-03, 5.04e-06, 6.35e-07, 1.28e-04, 2.09e-04, 3.35e-04]    [6.56e-04, 6.77e-04, 6.00e-04, 7.28e-03, 3.66e-04, 4.54e-03, 2.75e-03, 5.04e-06, 6.35e-07, 1.28e-04, 2.09e-04, 3.35e-04]    []  
18000     [2.99e-04, 3.79e-04, 7.62e-04, 7.04e-03, 3.48e-04, 4.41e-03, 2.21e-03, 5.67e-06, 2.12e-06, 1.05e-04, 1.67e-04, 3.54e-04]    [4.23e-04, 7.33e-04, 5.43e-04, 7.04e-03, 3.48e-04, 4.41e-03, 2.21e-03, 5.67e-06, 2.12e-06, 1.05e-04, 1.67e-04, 3.54e-04]    []  
19000     [3.63e-04, 3.22e-04, 6.78e-04, 6.57e-03, 3.43e-04, 4.23e-03, 1.88e-03, 3.57e-06, 7.83e-07, 7.54e-05, 1.50e-04, 3.99e-04]    [6.68e-04, 6.46e-04, 5.38e-04, 6.57e-03, 3.43e-04, 4.23e-03, 1.88e-03, 3.57e-06, 7.83e-07, 7.54e-05, 1.50e-04, 3.99e-04]    []  
20000     [3.02e-04, 3.36e-04, 7.17e-04, 6.48e-03, 2.96e-04, 3.89e-03, 1.67e-03, 6.25e-06, 1.63e-06, 8.80e-05, 1.37e-04, 3.51e-04]    [3.74e-04, 7.20e-04, 5.69e-04, 6.48e-03, 2.96e-04, 3.89e-03, 1.67e-03, 6.25e-06, 1.63e-06, 8.80e-05, 1.37e-04, 3.51e-04]    []  
21000     [3.23e-04, 3.49e-04, 6.97e-04, 5.83e-03, 3.42e-04, 3.66e-03, 1.66e-03, 3.87e-06, 3.33e-06, 7.11e-05, 1.49e-04, 3.45e-04]    [5.28e-04, 7.32e-04, 5.53e-04, 5.83e-03, 3.42e-04, 3.66e-03, 1.66e-03, 3.87e-06, 3.33e-06, 7.11e-05, 1.49e-04, 3.45e-04]    []  
22000     [3.35e-04, 3.32e-04, 6.92e-04, 5.73e-03, 3.93e-04, 3.19e-03, 1.57e-03, 5.70e-06, 1.95e-06, 6.93e-05, 1.59e-04, 3.51e-04]    [1.02e-03, 1.12e-03, 5.52e-04, 5.73e-03, 3.93e-04, 3.19e-03, 1.57e-03, 5.70e-06, 1.95e-06, 6.93e-05, 1.59e-04, 3.51e-04]    []  
23000     [3.04e-04, 3.18e-04, 7.07e-04, 5.40e-03, 3.98e-04, 3.04e-03, 1.47e-03, 4.09e-06, 2.98e-06, 6.16e-05, 1.57e-04, 3.52e-04]    [6.82e-04, 1.07e-03, 5.82e-04, 5.40e-03, 3.98e-04, 3.04e-03, 1.47e-03, 4.09e-06, 2.98e-06, 6.16e-05, 1.57e-04, 3.52e-04]    []  
24000     [2.71e-04, 3.71e-04, 7.29e-04, 5.32e-03, 3.61e-04, 2.78e-03, 1.26e-03, 4.75e-06, 1.39e-06, 6.27e-05, 1.32e-04, 3.33e-04]    [7.59e-04, 2.89e-03, 6.90e-04, 5.32e-03, 3.61e-04, 2.78e-03, 1.26e-03, 4.75e-06, 1.39e-06, 6.27e-05, 1.32e-04, 3.33e-04]    []  
25000     [2.30e-04, 3.18e-04, 7.35e-04, 5.07e-03, 3.67e-04, 2.75e-03, 1.19e-03, 7.37e-06, 1.19e-06, 6.54e-05, 1.26e-04, 3.50e-04]    [5.46e-04, 2.61e-03, 7.29e-04, 5.07e-03, 3.67e-04, 2.75e-03, 1.19e-03, 7.37e-06, 1.19e-06, 6.54e-05, 1.26e-04, 3.50e-04]    []  

Best model at step 25000:
  train loss: 1.12e-02
  test loss: 1.38e-02
  test metric: []

'train' took 823.377096 s

2.1.8. Plot Results (Adam + L-BFGS)¶

InĀ [29]:
samples = geom.random_points(500000)
result = model.predict(samples)
color_legend = [[0, 1.5], [-0.3, 0.3], [0, 35]]
for idx in range(3):
    plt.figure(figsize = (20, 4))
    plt.scatter(samples[:, 0],
                samples[:, 1],
                c = result[:, idx],
                cmap = 'jet',
                s = 2)
    plt.colorbar()
    plt.clim(color_legend[idx])
    plt.xlim((0-L/2, L-L/2))
    plt.ylim((0-D/2, D-D/2))
    plt.tight_layout()
    plt.show()### 7.2.8. Plot Results (Adam + L-BFGS)
InĀ [30]:
y0 = np.zeros([1000, 1])
y03 = np.ones([1000, 1])*0.3
yinv03 = np.ones([1000, 1])*(-0.3)
x = np.linspace(-1, 1, 1000).reshape(1000,1)
draw0 = np.hstack([x, y0])
draw03 = np.hstack([x, y03])
drawinv03 = np.hstack([x, yinv03])

result_draw0 = model.predict(draw0)
result_draw03 = model.predict(draw03)
result_drawinv03 = model.predict(drawinv03)
InĀ [31]:
# np.save('./data_plot/pdesmalldata_x', x)
# np.save('./data_plot/pdesmalldata_y0_u', result_draw0[:, 0])
# np.save('./data_plot/pdesmalldata_y0_v', result_draw0[:, 1])
# np.save('./data_plot/pdesmalldata_y0_p', result_draw0[:, 2])
# np.save('./data_plot/pdesmalldata_y03_u', result_draw03[:, 0])
# np.save('./data_plot/pdesmalldata_y03_v', result_draw03[:, 1])
# np.save('./data_plot/pdesmalldata_y03_p', result_draw03[:, 2])
# np.save('./data_plot/pdesmalldata_yinv03_u', result_drawinv03[:, 0])
# np.save('./data_plot/pdesmalldata_yinv03_v', result_drawinv03[:, 1])
# np.save('./data_plot/pdesmalldata_yinv03_p', result_drawinv03[:, 2])
InĀ [34]:
# result_total = model.predict(observe_x)
# np.save('./data_plot/pdesmalldata_total_x', observe_x[:, 0])
# np.save('./data_plot/pdesmalldata_total_y', observe_x[:, 1])
# np.save('./data_plot/pdesmalldata_total_u', result_total[:, 0])
# np.save('./data_plot/pdesmalldata_total_v', result_total[:, 1])
# np.save('./data_plot/pdesmalldata_total_p', result_total[:, 2])
InĀ [32]:
import pandas as pd
x_vel_xcor = pd.read_table('/mnt/disk1/seungmin/PINN/lecture/data/cae/x_vel_xcor_Re2_L2.txt')
x_vel_ycor = pd.read_table('/mnt/disk1/seungmin/PINN/lecture/data/cae/x_vel_ycor_Re2_L2.txt')
y_vel_xcor = pd.read_table('/mnt/disk1/seungmin/PINN/lecture/data/cae/y_vel_xcor_Re2_L2.txt')
y_vel_ycor = pd.read_table('/mnt/disk1/seungmin/PINN/lecture/data/cae/y_vel_ycor_Re2_L2.txt') 
p_xcor = pd.read_table('/mnt/disk1/seungmin/PINN/lecture/data/cae/p_xcor_Re2_L2.txt')
p_ycor = pd.read_table('/mnt/disk1/seungmin/PINN/lecture/data/cae/p_ycor_Re2_L2.txt') 
x_vel_xcor = np.array(x_vel_xcor)
x_vel_ycor = np.array(x_vel_ycor)
y_vel_xcor = np.array(y_vel_xcor)
y_vel_ycor = np.array(y_vel_ycor)
p_xcor = np.array(p_xcor)
p_ycor = np.array(p_ycor)
InĀ [33]:
observe_x = np.hstack([x_vel_xcor[:, 0].reshape(-1, 1), x_vel_ycor[:, 0].reshape(-1, 1)])

xvel_test = x_vel_xcor[:, 1].reshape(-1, 1)
yvel_test = y_vel_xcor[:, 1].reshape(-1, 1)
p_test = p_xcor[:, 1].reshape(-1, 1)
observe_y = np.hstack([xvel_test, yvel_test, p_test])
InĀ [94]:
color_legend = [[0, 1.5], [-0.3, 0.3], [0, 35]]
for idx in range(3):
    plt.figure(figsize = (20, 4))
    plt.scatter(observe_x[:, 0],
                observe_x[:, 1],
                c = observe_y[:, idx],
                cmap = 'jet',
                s = 6.5)
    plt.colorbar()
    plt.clim(color_legend[idx])
    plt.xlim((0-L/2, L-L/2))
    plt.ylim((0-D/2, D-D/2))
    plt.tight_layout()
    plt.show()
InĀ [3]:
%%javascript
$.getScript('https://kmahelona.github.io/ipython_notebook_goodies/ipython_notebook_toc.js')